package com.xbongbong.saas.script.tempenum.product;

import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.LinkedAttrPoJo;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.LinkInfoPojo;
import com.xbongbong.paas.field.LinkKeyFieldInfoPojo;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.product.BomFinishProductEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/10/12 10:32
 * @since v1.0
 */
@Getter
public enum TempBomFinishProductEnum {
    PRODUCT(BomFinishProductEnum.PRODUCT),
    NUM(BomFinishProductEnum.NUM),
    MEMO(BomFinishProductEnum.MEMO),
    UNIT(BomFinishProductEnum.UNIT),
    ;

    private BomFinishProductEnum bomFinishProductEnum;

    TempBomFinishProductEnum(BomFinishProductEnum bomFinishProductEnum) {
        this.bomFinishProductEnum = bomFinishProductEnum;
    }

    public static void initProduct(FieldAttrEntity fieldAttrEntity, List<LinkedAttrPoJo> linkedAttrPoJoList,List<LinkedAttrPoJo> linkedShowPoJoList, PaasFormEntityExt paasFormEntity){
        LinkInfoPojo linkInfoPojo = new LinkInfoPojo();
        linkInfoPojo.setLinkBusinessType(XbbRefTypeEnum.PRODUCT.getCode());
        linkInfoPojo.setLinkedAttr(linkedAttrPoJoList);
        linkInfoPojo.setLinkSaasMark(SaasMarkEnum.SAAS.getCode());
        linkInfoPojo.setLinkKey(linkedAttrPoJoList.get(1).getAttr());
        linkInfoPojo.setLinkFormId(paasFormEntity.getId());
        linkInfoPojo.setLinkMenuId(paasFormEntity.getMenuId());
        linkInfoPojo.setLinkAppId(paasFormEntity.getAppId());
        linkInfoPojo.setCondition(new ArrayList<>());
        LinkKeyFieldInfoPojo linkKeyFieldInfoPojo = new LinkKeyFieldInfoPojo();
        BeanUtil.copyProperties(linkedAttrPoJoList.get(1),linkKeyFieldInfoPojo);
        linkInfoPojo.setLinkKeyAttr(linkKeyFieldInfoPojo);
        linkInfoPojo.setLinkedShowAttr(linkedShowPoJoList);
        fieldAttrEntity.setLinkInfo(linkInfoPojo);
        fieldAttrEntity.setShowEditable(1);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_VISIBLE_PERMISSION.getAlias()));
    }

    public static void initNum(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setIsForbidden(1);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultValue(1);
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.CUSTOM.getAlias());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setNumAccuracyAndScopeHide(1);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_MONEY_TYPE.getAlias()));
    }

    public static void initUnit(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setEditable(0);
        List<String> settingList = Arrays.asList(ForbiddenSettingEnum.DISABLE_ITEMS.getAlias(),
                ForbiddenSettingEnum.DISABLE_RULE.getAlias());
        fieldAttrEntity.setForbiddenSettingList(settingList);
    }

    public static void initMemo(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setIsForbidden(1);
        fieldAttrEntity.setShowEditable(1);
    }

}
